import java.util.Scanner;

//题目：计算字符串中子串出现的次数
public class Test43 {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        System.out.println("请输入字符串：");
        String str1 = console.nextLine();
        System.out.println("请输入需要检索的字符串：");
        String str2 = console.nextLine();
        int count = checkString(str1, str2);
        System.out.println("字符串" + str1 + "中" + str2 + "出现了" + count + "次。");
    }

    public static int checkString(String str1, String str2) {
        int count = 0;
        int num = 0;
        while ((num = str1.indexOf(str2, num)) != -1) {
            count++;
            num += str2.length();
        }
        return count;
    }
}
